package cn.ds.general.sql.util;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DataSourceConfig {
    @Getter
    private static HikariDataSource dataSource;

    static {
        Properties props = new Properties();
        InputStream input = null;

        try {
            input = DataSourceConfig.class.getClassLoader().getResourceAsStream("database.properties");
            props.load(input);

            HikariConfig config = new HikariConfig();
            config.setJdbcUrl(props.getProperty("db.url"));
            config.setUsername(props.getProperty("db.username"));
            config.setPassword(props.getProperty("db.password"));
            config.setDriverClassName(props.getProperty("db.driverClassName"));
            config.setMaximumPoolSize(Integer.parseInt(props.getProperty("db.maxPoolSize")));
            // 其他配置...

            dataSource = new HikariDataSource(config);
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}